home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
NewsTicker.sit
/
NewsTicker
/
source code
/
Extractors
/
TickerCheckWebs.cp
< prev
next >
Wrap
Text File
|
1997-06-21
|
5KB
|
170 lines
/*------------------------------------------------------------------------------
#
# NewsTicker, my Hack for 1997
#
# TickerCheckWebs.cp - Check to see if web pages have changed.
#
------------------------------------------------------------------------------*/
#include "TickerGlobals.h" /* bring in all the #defines for NewsTicker */
#include "TickerCheckWebs.h"
#include "TickerReadHeadlines.h"
#include "TickerWindowHandler.h"
#include "HTMLExtractor.h"
// update every 15 minutes
#define kWebCheckDuration 900
// Globals for Web Checking
static unsigned long gWebCheckTime = 0;
static short nextEntryToCheck = 0;
//
// For any web page (passed as address, not URL) get the last modified date
//
void GetModifiedDate( sMyDataPtr gGlobalsPtr, char* thename, Str31 LastModStr )
{
Boolean DidAny = false;
HTMLExtractor* thehandler;
thehandler = new HTMLExtractor(thename, 0, gGlobalsPtr);
thehandler->ReadLastModified();
thehandler->GetLastModified(LastModStr);
delete thehandler;
InitCursor();
}
void UpdateChangedWebs(sMyDataPtr gGlobalsPtr)
{
short index;
short destindex;
Str255 tempstr;
// Delete all entries with cicnResID = kWebIconID
destindex = 0;
for (index = 0; index < gGlobalsPtr->MsgCount; index++)
{
if (gGlobalsPtr->theHeadlines[index].cicnResID!=kWebIconID) //don't delete it
{
if (index!=destindex) //copy down if we need to
{
gGlobalsPtr->theHeadlines[destindex] = gGlobalsPtr->theHeadlines[index];
}
destindex++;
}
}
gGlobalsPtr->MsgCount = destindex;
// Now copy the entries we've changed accumulated out
for (index = 0; index<numWebPages; index++) // copy the entries off
{
if (gThePrefs.WebPageDisplay[index]&&(gGlobalsPtr->MsgCount<maxHeadlines))
{ //add it!
PLstrcpy(tempstr, "\phttp://"); //form the URL
PLstrcat(tempstr, gThePrefs.WebPageAddress[index]);
destindex = gGlobalsPtr->MsgCount;
PLstrcpy(gGlobalsPtr->theHeadlines[destindex].Subject,
gThePrefs.WebPageAddress[index]);
PLstrcpy(gGlobalsPtr->theHeadlines[destindex].URL, tempstr);
gGlobalsPtr->theHeadlines[destindex].cicnResID = kWebIconID;
gGlobalsPtr->MsgCount++;
}
}
}
void UpdateAWebEntry(sMyDataPtr gGlobalsPtr, short whichmsg)
{
short index, index2;
for (index = 0; index<numWebPages; index++)
{
if (gThePrefs.WebPageDisplay[index])
{
if (EqualString(gThePrefs.WebPageAddress[index],
gGlobalsPtr->theHeadlines[whichmsg].Subject, false, false))
{
LaunchURL(gGlobalsPtr->theHeadlines[whichmsg].URL);
gThePrefs.WebPageDisplay[index] = false; //OK, we've read this
gGlobalsPtr->MsgCount--;
for (index2 = whichmsg; index2<gGlobalsPtr->MsgCount; index2++) //Remove us from the scrolling list
{
gGlobalsPtr->theHeadlines[index2] = gGlobalsPtr->theHeadlines[index2+1];
}
CalcOffsets(gGlobalsPtr);
return;
}
}
}
}
void CheckChangedWebPages(sMyDataPtr gGlobalsPtr)
{
unsigned long now;
Str31 newModifiedTime;
Str255 tempstr;
Boolean NewDoDisplay;
short index2;
short whichitem;
GetDateTime(&now);
if (!gWebCheckTime) //first call, don't do anything
{
gWebCheckTime = now + kWebCheckDuration;
return;
}
if (now<gWebCheckTime) //time to check the next entry?
return;
gWebCheckTime = now + kWebCheckDuration;
nextEntryToCheck++;
if (nextEntryToCheck>=numWebPages)
nextEntryToCheck = 0;
if (gThePrefs.WebPageAddress[nextEntryToCheck][0]) //Only check those entries that have an address
{
PLstrcpy(tempstr, gThePrefs.WebPageAddress[nextEntryToCheck]);
tempstr[tempstr[0]+1] = 0; //make it a nice c string
GetModifiedDate( gGlobalsPtr, (char*)(&tempstr[1]), newModifiedTime); //get the modified time
if (!newModifiedTime[0]) //no date
NewDoDisplay = true;
else
{
NewDoDisplay = !EqualString(newModifiedTime, gThePrefs.WebPageLastDate[nextEntryToCheck], false, false);
PLstrcpy(gThePrefs.WebPageLastDate[nextEntryToCheck], newModifiedTime);
}
if (NewDoDisplay && (!gThePrefs.WebPageDisplay[nextEntryToCheck])) //need to start displaying it?
{
gThePrefs.WebPageDisplay[nextEntryToCheck] = true;
for (index2 = gGlobalsPtr->MsgCount; index2>0; index2--) //Open up entry 0
{
gGlobalsPtr->theHeadlines[index2] = gGlobalsPtr->theHeadlines[index2-1];
}
gGlobalsPtr->MsgCount++; //we're going to add us at the start
PLstrcpy(tempstr, "\phttp://"); //form the URL
PLstrcat(tempstr, gThePrefs.WebPageAddress[nextEntryToCheck]);
PLstrcpy(gGlobalsPtr->theHeadlines[0].Subject,
gThePrefs.WebPageAddress[nextEntryToCheck]);
PLstrcpy(gGlobalsPtr->theHeadlines[0].URL, tempstr);
gGlobalsPtr->theHeadlines[0].cicnResID = kWebIconID;
CalcOffsets(gGlobalsPtr);
}
}
}